home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / php / pear / Net / DNS.php < prev    next >
PHP Script  |  2004-03-24  |  15KB  |  504 lines

  1. <?php
  2. /*
  3.  *  Module written/ported by Eric Kilfoil <eric@ypass.net>
  4.  * 
  5.  *  This is the copyright notice from the PERL Net::DNS module:
  6.  *
  7.  *  Copyright (c) 1997-2000 Michael Fuhr.  All rights reserved.  This
  8.  *  program is free software; you can redistribute it and/or modify it
  9.  *  under the same terms as Perl itself.
  10.  *
  11.  *  The majority of this is _NOT_ my code.  I simply ported it from the
  12.  *  PERL Net::DNS module.  
  13.  *
  14.  *  The author of the Net::DNS module is Michael Fuhr <mike@fuhr.org>
  15.  *  http://www.fuhr.org/~mfuhr/perldns/
  16.  *
  17.  *  I _DO_ maintain this code, and Miachael Fuhr has nothing to with the
  18.  *  porting of this code to PHP.  Any questions directly related to this
  19.  *  class library should be directed to me.
  20.  *
  21.  *  I'll be setting up a CVS repository for this class soon.  The more
  22.  *  emails i get concerning this, the more apt i am to do it.
  23.  *
  24.  *  License Information:
  25.  *
  26.  *    Net_DNS:  A resolver library for PHP
  27.  *    Copyright (C) 2002 Eric Kilfoil eric@ypass.net
  28.  *
  29.  *    This library is free software; you can redistribute it and/or
  30.  *    modify it under the terms of the GNU Lesser General Public
  31.  *    License as published by the Free Software Foundation; either
  32.  *    version 2.1 of the License, or (at your option) any later version.
  33.  *
  34.  *    This library is distributed in the hope that it will be useful,
  35.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  36.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  37.  *    Lesser General Public License for more details.
  38.  *
  39.  *    You should have received a copy of the GNU Lesser General Public
  40.  *    License along with this library; if not, write to the Free Software
  41.  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  42.  */
  43.  
  44. /* Include information {{{ */
  45.  
  46.     $phpdns_basedir = "Net";
  47.     require_once("$phpdns_basedir/DNS/Header.php");
  48.     require_once("$phpdns_basedir/DNS/Question.php");
  49.     require_once("$phpdns_basedir/DNS/Packet.php");
  50.     require_once("$phpdns_basedir/DNS/Resolver.php");
  51.     require_once("$phpdns_basedir/DNS/RR.php");
  52.  
  53. /* }}} */
  54. /* GLOBAL VARIABLE definitions {{{ */
  55.  
  56. // Used by the Net_DNS_Resolver object to generate an ID
  57. mt_srand((double) microtime() * 10000);
  58. $_Net_DNS_packet_id = (int)mt_rand(0, 65535);
  59.  
  60. /* }}} */
  61. /* Net_DNS object definition (incomplete) {{{ */
  62. /**
  63.  * Initializes a resolver object
  64.  *
  65.  * Net_DNS allows you to query a nameserver for DNS  lookups.  It bypasses the
  66.  * system resolver library  entirely, which allows you to query any nameserver,
  67.  * set your own values for retries, timeouts, recursion,  etc.
  68.  *
  69.  * @author Eric Kilfoil <eric@ypass.net>
  70.  * @package Net_DNS
  71.  * @version 0.01alpha
  72.  */
  73. class Net_DNS
  74. {
  75.     /* class variable definitions {{{ */
  76.     /**
  77.      * A default resolver object created on instantiation
  78.      *
  79.      * @var object Net_DNS_Resolver
  80.      */
  81.     var $resolver;
  82.     var $VERSION = "0.01";
  83.     var $PACKETSZ = 512;
  84.     var $HFIXEDSZ = 12;
  85.     var $QFIXEDSZ = 4;
  86.     var $RRFIXEDSZ = 10;
  87.     var $INT32SZ = 4;
  88.     var $INT16SZ = 2;
  89.     /* }}} */
  90.     /* class constructor - Net_DNS() {{{ */
  91.     /**
  92.      * Initializes a resolver object
  93.      *
  94.      * @see Net_DNS_Resolver
  95.      */
  96.     function Net_DNS()
  97.     {
  98.         $this->resolver = new Net_DNS_Resolver();
  99.     }
  100.     /* }}} */
  101.     /* Net_DNS::opcodesbyname() {{{ */
  102.     /**
  103.      * Translates opcode names to integers
  104.      *
  105.      * Translates the name of a DNS OPCODE into it's assigned  number
  106.      * listed in RFC1035, RFC1996, or RFC2136. Valid  OPCODES are:
  107.      * <ul>
  108.      *   <li>QUERY   
  109.      *   <li>IQUERY   
  110.      *   <li>STATUS   
  111.      *   <li>NS_NOTIFY_OP   
  112.      *   <li>UPDATE
  113.      * <ul>
  114.      * 
  115.      * @param   string  $opcode A DNS Packet OPCODE name
  116.      * @return  integer The integer value of an OPCODE
  117.      * @see     Net_DNS::opcodesbyval()
  118.      */
  119.     function opcodesbyname($opcode)
  120.     {
  121.         $op = array(
  122.                 "QUERY"        => 0,   // RFC 1035
  123.                 "IQUERY"       => 1,   // RFC 1035
  124.                 "STATUS"       => 2,   // RFC 1035
  125.                 "NS_NOTIFY_OP" => 4,   // RFC 1996
  126.                 "UPDATE"       => 5,   // RFC 2136
  127.                 );
  128.         if (! strlen($op[$opcode])) {
  129.             $op[$opcode] = NULL;
  130.         }
  131.         return($op[$opcode]);
  132.     }
  133.  
  134.     /* }}} */
  135.     /* Net_DNS::opcodesbyval() {{{*/
  136.     /**
  137.      * Translates opcode integers into names
  138.      *
  139.      * Translates the integer value of an opcode into it's name
  140.      * 
  141.      * @param   integer $opcodeval  A DNS packet opcode integer
  142.      * @return  string  The name of the OPCODE
  143.      * @see     Net_DNS::opcodesbyname()
  144.      */
  145.     function opcodesbyval($opcodeval)
  146.     {
  147.         $opval = array(
  148.                 0 => "QUERY",
  149.                 1 => "IQUERY",
  150.                 2 => "STATUS",
  151.                 4 => "NS_NOTIFY_OP",
  152.                 5 => "UPDATE",
  153.                 );
  154.         if (! strlen($opval[$opcodeval])) {
  155.             $opval[$opcodeval] = NULL;
  156.         }
  157.         return($opval[$opcodeval]);
  158.     }
  159.  
  160.     /*}}}*/
  161.     /* Net_DNS::rcodesbyname() {{{*/
  162.     /**
  163.      * Translates rcode names to integers
  164.      *
  165.      * Translates the name of a DNS RCODE (result code) into it's assigned number.
  166.      * <ul>
  167.      *   <li>NOERROR   
  168.      *   <li>FORMERR   
  169.      *   <li>SERVFAIL   
  170.      *   <li>NXDOMAIN   
  171.      *   <li>NOTIMP   
  172.      *   <li>REFUSED   
  173.      *   <li>YXDOMAIN   
  174.      *   <li>YXRRSET   
  175.      *   <li>NXRRSET   
  176.      *   <li>NOTAUTH   
  177.      *   <li>NOTZONE
  178.      * <ul>
  179.      * 
  180.      * @param   string  $rcode  A DNS Packet RCODE name
  181.      * @return  integer The integer value of an RCODE
  182.      * @see     Net_DNS::rcodesbyval()
  183.      */
  184.     function rcodesbyname($rcode)
  185.     {
  186.         $rc = array(
  187.                 "NOERROR"   => 0,   // RFC 1035
  188.                 "FORMERR"   => 1,   // RFC 1035
  189.                 "SERVFAIL"  => 2,   // RFC 1035
  190.                 "NXDOMAIN"  => 3,   // RFC 1035
  191.                 "NOTIMP"    => 4,   // RFC 1035
  192.                 "REFUSED"   => 5,   // RFC 1035
  193.                 "YXDOMAIN"  => 6,   // RFC 2136
  194.                 "YXRRSET"   => 7,   // RFC 2136
  195.                 "NXRRSET"   => 8,   // RFC 2136
  196.                 "NOTAUTH"   => 9,   // RFC 2136
  197.                 "NOTZONE"   => 10,    // RFC 2136
  198.                 );
  199.         if (! strlen($rc[$rcode])) {
  200.             $rc[$rcode] = NULL;
  201.         }
  202.         return($rc[$rcode]);
  203.     }
  204.  
  205.     /*}}}*/
  206.     /* Net_DNS::rcodesbyval() {{{*/
  207.     /**
  208.      * Translates rcode integers into names
  209.      *
  210.      * Translates the integer value of an rcode into it's name
  211.      * 
  212.      * @param   integer $rcodeval   A DNS packet rcode integer
  213.      * @return  string  The name of the RCODE
  214.      * @see     Net_DNS::rcodesbyname()
  215.      */
  216.     function rcodesbyval($rcodeval)
  217.     {
  218.         $rc = array(
  219.                 0 => "NOERROR",
  220.                 1 => "FORMERR",
  221.                 2 => "SERVFAIL",
  222.                 3 => "NXDOMAIN",
  223.                 4 => "NOTIMP",
  224.                 5 => "REFUSED",
  225.                 6 => "YXDOMAIN",
  226.                 7 => "YXRRSET",
  227.                 8 => "NXRRSET",
  228.                 9 => "NOTAUTH",
  229.                 10 => "NOTZONE",
  230.                 );
  231.         if (! strlen($rc[$rcodeval])) {
  232.             $rc[$rcodeval] = NULL;
  233.         }
  234.         return($rc[$rcodeval]);
  235.     }
  236.  
  237.     /*}}}*/
  238.     /* Net_DNS::typesbyname() {{{*/
  239.     /**
  240.      * Translates RR type names into integers
  241.      *
  242.      * Translates a Resource Record from it's name to it's  integer value.
  243.      * Valid resource record types are:
  244.      *
  245.      * <ul>
  246.      *   <li>A   
  247.      *   <li>NS   
  248.      *   <li>MD   
  249.      *   <li>MF   
  250.      *   <li>CNAME   
  251.      *   <li>SOA   
  252.      *   <li>MB   
  253.      *   <li>MG   
  254.      *   <li>MR   
  255.      *   <li>NULL   
  256.      *   <li>WKS   
  257.      *   <li>PTR   
  258.      *   <li>HINFO   
  259.      *   <li>MINFO   
  260.      *   <li>MX   
  261.      *   <li>TXT   
  262.      *   <li>RP   
  263.      *   <li>AFSDB   
  264.      *   <li>X25   
  265.      *   <li>ISDN   
  266.      *   <li>RT   
  267.      *   <li>NSAP   
  268.      *   <li>NSAP_PTR   
  269.      *   <li>SIG   
  270.      *   <li>KEY   
  271.      *   <li>PX   
  272.      *   <li>GPOS   
  273.      *   <li>AAAA   
  274.      *   <li>LOC   
  275.      *   <li>NXT   
  276.      *   <li>EID   
  277.      *   <li>NIMLOC   
  278.      *   <li>SRV   
  279.      *   <li>ATMA   
  280.      *   <li>NAPTR   
  281.      *   <li>TSIG   
  282.      *   <li>UINFO   
  283.      *   <li>UID   
  284.      *   <li>GID   
  285.      *   <li>UNSPEC   
  286.      *   <li>IXFR   
  287.      *   <li>AXFR   
  288.      *   <li>MAILB   
  289.      *   <li>MAILA   
  290.      *   <li>ANY
  291.      * <ul>
  292.      * 
  293.      * @param   string  $rrtype A DNS packet RR type name   
  294.      * @return  integer The integer value of an RR type
  295.      * @see     Net_DNS::typesbyval()
  296.      */
  297.     function typesbyname($rrtype)
  298.     {
  299.         $rc = array(
  300.                 "A"             => 1,
  301.                 "NS"            => 2,
  302.                 "MD"            => 3,
  303.                 "MF"            => 4,
  304.                 "CNAME"         => 5,
  305.                 "SOA"           => 6,
  306.                 "MB"            => 7,
  307.                 "MG"            => 8,
  308.                 "MR"            => 9,
  309.                 "NULL"          => 10,
  310.                 "WKS"           => 11,
  311.                 "PTR"           => 12,
  312.                 "HINFO"         => 13,
  313.                 "MINFO"         => 14,
  314.                 "MX"            => 15,
  315.                 "TXT"           => 16,
  316.                 "RP"            => 17,
  317.                 "AFSDB"         => 18,
  318.                 "X25"           => 19,
  319.                 "ISDN"          => 20,
  320.                 "RT"            => 21,
  321.                 "NSAP"          => 22,
  322.                 "NSAP_PTR"      => 23,
  323.                 "SIG"           => 24,
  324.                 "KEY"           => 25,
  325.                 "PX"            => 26,
  326.                 "GPOS"          => 27,
  327.                 "AAAA"          => 28,
  328.                 "LOC"           => 29,
  329.                 "NXT"           => 30,
  330.                 "EID"           => 31,
  331.                 "NIMLOC"        => 32,
  332.                 "SRV"           => 33,
  333.                 "ATMA"          => 34,
  334.                 "NAPTR"         => 35,
  335.                 "UINFO"         => 100,
  336.                 "UID"           => 101,
  337.                 "GID"           => 102,
  338.                 "UNSPEC"        => 103,
  339.                 "TSIG"          => 250,
  340.                 "IXFR"          => 251,
  341.                 "AXFR"          => 252,
  342.                 "MAILB"         => 253,
  343.                 "MAILA"         => 254,
  344.                 "ANY"           => 255,
  345.                 );
  346.                 if (! strlen($rc[$rrtype])) {
  347.                     $rc[$rrtype] = NULL;
  348.                 }
  349.                 return($rc[$rrtype]);
  350.     }
  351.  
  352.     /*}}}*/
  353.     /* Net_DNS::typesbyval() {{{*/
  354.     /**
  355.      * Translates RR type integers into names
  356.      *
  357.      * Translates the integer value of an RR type into it's name
  358.      * 
  359.      * @param   integer $rrtypeval  A DNS packet RR type integer
  360.      * @return  string  The name of the RR type
  361.      * @see     Net_DNS::typesbyname()
  362.      */
  363.     function typesbyval($rrtypeval)
  364.     {
  365.         $rc = array(
  366.                 1 => "A",
  367.                 2 => "NS",
  368.                 3 => "MD",
  369.                 4 => "MF",
  370.                 5 => "CNAME",
  371.                 6 => "SOA",
  372.                 7 => "MB",
  373.                 8 => "MG",
  374.                 9 => "MR",
  375.                 10 => "NULL",
  376.                 11 => "WKS",
  377.                 12 => "PTR",
  378.                 13 => "HINFO",
  379.                 14 => "MINFO",
  380.                 15 => "MX",
  381.                 16 => "TXT",
  382.                 17 => "RP",
  383.                 18 => "AFSDB",
  384.                 19 => "X25",
  385.                 20 => "ISDN",
  386.                 21 => "RT",
  387.                 22 => "NSAP",
  388.                 23 => "NSAP_PTR",
  389.                 24 => "SIG",
  390.                 25 => "KEY",
  391.                 26 => "PX",
  392.                 27 => "GPOS",
  393.                 28 => "AAAA",
  394.                 29 => "LOC",
  395.                 30 => "NXT",
  396.                 31 => "EID",
  397.                 32 => "NIMLOC",
  398.                 33 => "SRV",
  399.                 34 => "ATMA",
  400.                 35 => "NAPTR",
  401.                 100 => "UINFO",
  402.                 101 => "UID",
  403.                 102 => "GID",
  404.                 103 => "UNSPEC",
  405.                 250 => "TSIG",
  406.                 251 => "IXFR",
  407.                 252 => "AXFR",
  408.                 253 => "MAILB",
  409.                 254 => "MAILA",
  410.                 255 => "ANY",
  411.                 );
  412.                 if (! strlen($rc[$rrtypeval])) {
  413.                     $rc[$rrtypeval] = NULL;
  414.                 }
  415.                 return($rc[$rrtypeval]);
  416.     }
  417.  
  418.     /*}}}*/
  419.     /* Net_DNS::classesbyname() {{{*/
  420.     /**
  421.      * translates a DNS class from it's name to it's  integer value. Valid
  422.      * class names are:
  423.      * <ul>
  424.      *   <li>IN   
  425.      *   <li>CH   
  426.      *   <li>HS   
  427.      *   <li>NONE   
  428.      *   <li>ANY
  429.      * </ul>
  430.      * 
  431.      * @param   string  $class  A DNS packet class type
  432.      * @return  integer The integer value of an class type
  433.      * @see     Net_DNS::classesbyval()
  434.      */
  435.     function classesbyname($class)
  436.     {
  437.         $rc = array(
  438.                 "IN"            => 1,
  439.                 "CH"            => 3,
  440.                 "HS"            => 4,
  441.                 "NONE"          => 254,
  442.                 "ANY"           => 255
  443.                 );
  444.         if (! strlen($rc[$class])) {
  445.             $rc[$class] = NULL;
  446.         }
  447.         return($rc[$class]);
  448.     }
  449.  
  450.     /*}}}*/
  451.     /* Net_DNS::classesbyval() {{{*/
  452.     /**
  453.      * Translates RR class integers into names
  454.      *
  455.      * Translates the integer value of an RR class into it's name
  456.      * 
  457.      * @param   integer $classval   A DNS packet RR class integer
  458.      * @return  string  The name of the RR class
  459.      * @see     Net_DNS::classesbyname()
  460.      */
  461.     function classesbyval($classval)
  462.     {
  463.         $rc = array(
  464.                 1 => "IN",
  465.                 3 => "CH",
  466.                 4 => "HS",
  467.                 254 => "NONE",
  468.                 255 => "ANY"
  469.                 );
  470.         if (! strlen($rc[$classval])) {
  471.             $rc[$classval] = NULL;
  472.         }
  473.         return($rc[$classval]);
  474.     }
  475.  
  476.     /*}}}*/
  477.     /* not completed - Net_DNS::mx() {{{*/
  478.     /*}}}*/
  479.     /* not completed - Net_DNS::yxrrset() {{{*/
  480.     /*}}}*/
  481.     /* not completed - Net_DNS::nxrrset() {{{*/
  482.     /*}}}*/
  483.     /* not completed - Net_DNS::yxdomain() {{{*/
  484.     /*}}}*/
  485.     /* not completed - Net_DNS::nxdomain() {{{*/
  486.     /*}}}*/
  487.     /* not completed - Net_DNS::rr_add() {{{*/
  488.     /*}}}*/
  489.     /* not completed - Net_DNS::rr_del() {{{*/
  490.     /*}}}*/
  491. }
  492. /* }}} */
  493. /* VIM Settings {{{
  494.  * Local variables:
  495.  * tab-width: 4
  496.  * c-basic-offset: 4
  497.  * soft-stop-width: 4
  498.  * c indent on
  499.  * End:
  500.  * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et
  501.  * vim<600: sw=4 ts=4
  502.  * }}} */
  503. ?>
  504.